package com.xls.aclservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xls.base.model.SysLog;
import com.xls.base.mapper.SysLogMapper;
import com.xls.aclservice.service.SysLogService;
import com.xls.aclservice.vo.SysLogQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    @Override
    public Page<SysLog> getSysLogPage(Integer page, Integer limit, SysLogQuery sysLogQuery) {
        QueryWrapper<SysLog> sysLogQueryWrapper = new QueryWrapper<>();
        String title = sysLogQuery.getTitle();
        String username = sysLogQuery.getUsername();
        String begin = sysLogQuery.getBegin();
        String end = sysLogQuery.getEnd();
        sysLogQueryWrapper
                .likeRight(!StringUtils.isEmpty(title), "title", title)
                .likeRight(!StringUtils.isEmpty(username), "username", username)
                .gt(!StringUtils.isEmpty(begin), "gmt_create", begin)
                .lt(!StringUtils.isEmpty(end), "gmt_create", end)
                .eq("is_deleted", 0)
                .orderByDesc("gmt_create");
        return sysLogMapper.selectPage(new Page<>(page, limit), sysLogQueryWrapper);
    }
}
